﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;
using JAAF.Collections;

namespace JAAF.UI
{
    /// <summary>
    /// Defines an interface for a user interface component that hosts / displays <see cref="IView">views</see>.
    /// </summary>
    public interface IViewspace
    {
        #region Events

        /// <summary>
        /// Fires when a view hosted by this workspace is closing.
        /// </summary>
        event EventHandler<ViewspaceCancelEventArgs> ViewClosing;

        /// <summary>
        /// Fires when a view is activated.
        /// </summary>
        event EventHandler<ViewspaceEventArgs> ViewActivated;

        #endregion


        #region Properties

        /// <summary>
        /// A list of the views that are currently hosted inside this workspace.
        /// </summary>
        ReadOnlyKeyedCollection<string, IView> Views
        { get; }

        /// <summary>
        /// Gets the view that is hosted inside this workspace and currently has the focus.
        /// </summary>
        object ActiveView
        { get; }

        #endregion


        #region Methods

        /// <summary>
        /// Displays a <see cref="IView">view</see> inside this workspace.
        /// </summary>
        /// <param name="_oView">The <see cref="IView">view</see> to display.</param>
        void ShowView(IView _oView);

        /// <summary>
        /// Closes a <see cref="IView">view</see>. Disposing it is the responsibility of the caller.
        /// </summary>
        /// <param name="IView">The <see cref="IView">view</see> to close.</param>
        void CloseView(IView _oView);

        /// <summary>
        /// Activates and sets the focus onto a <see cref="IView">view</see>
        /// that is allready displayed inside this workspace.
        /// </summary>
        /// <param name="_oView"></param>
        void ActivateView(IView _oView);

        /// <summary>
        /// Hides a <see cref="IView">view</see> that is currently
        /// displayed inside this workspace.
        /// </summary>
        /// <remarks> This method affects only the <see cref="IView">views</see>
        /// that have been allready <see cref="IViewspace.Show">shown</see>
        /// inside this workspace.
        /// </remarks>
        /// <param name="_oView">The <see cref="IView">view</see> to hide.</param>
        void HideView(IView _oView);

        /// <summary>
        /// Makes a <see cref="IView">view</see> active, 
        /// so that it can interract with the user.
        /// </summary>
        /// <remarks>
        /// This method affects only the <see cref="IView">views</see>
        /// that have been allready <see cref="IViewspace.Show">shown</see>
        /// inside this workspace.
        /// </remarks>
        /// <param name="_oView">The <see cref="IView"/> to activate.</param>
        void EnableView(IView _oView);

        /// <summary>
        /// Disables <see cref="IView">view</see> so that it cannot interract
        /// with the user. However, the view remains visible.
        /// </summary>
        /// <remarks>
        /// This method affects only the <see cref="IView">views</see>
        /// that have been allready <see cref="IViewspace.Show">shown</see>
        /// inside this workspace.
        /// </remarks>
        /// <param name="_oView">The <see cref="IView">view</see> to disable.</param>
        void DisableView(IView _oView);

        #endregion

    }


    public class ViewspaceEventArgs : EventArgs
    {
        public IView View;

        public ViewspaceEventArgs(IView _oView)
        {
            this.View = _oView;
        }
    }


    public class ViewspaceCancelEventArgs : CancelEventArgs
    {
        public IView View;

        public ViewspaceCancelEventArgs(IView _oView)
        {
            this.View = _oView;
        }

        public ViewspaceCancelEventArgs(IView _oView, bool _bCancel)
            : base(_bCancel)
        {
        }
    }
}
